package Frame.screen;

import FCRendering.FCRConstants;
import FCRendering.FCRMaster;
import FCRendering.ImageUtil;

import java.awt.*;

import static FCRendering.FCRMaster.fcv;
import static FCRendering.FCRMaster.langLib;

public class UseTankMenuScreen extends IScreen{

    Font font1;
    @Override
    public void dispatchPaintComponent(Graphics g, FCRMaster fcrMaster) {
        // 渲染乘降菜单
        if (fcv.isOpenUseTankMenu()) {
            g.setColor(Color.black);
            g.setFont(font1);
            g.drawImage(ImageUtil.getImage("gamesayselectmenuhead"), fcv.getTankMenuCoorX(), fcv.getTankMenuCoorY(),
                    (int) (184 * fcv.getProportion()), (int) (19 * fcv.getProportion()), this);
            g.drawImage(ImageUtil.getImage("gamesayselectmenubody"), fcv.getTankMenuCoorX(),
                    (int) (19 * fcv.getProportion()) + fcv.getTankMenuCoorY(), (int) (184 * fcv.getProportion()), (int) (44 * fcv.getProportion()),
                    this);
            g.drawImage(ImageUtil.getImage("gamesayselectbutton"), fcv.getTankMenuCoorX() + (int) (18 * fcv.getProportion()),
                    (int) (21 * fcv.getProportion()) + fcv.getTankMenuCoorY(), (int) (149 * fcv.getProportion()), (int) (40 * fcv.getProportion()),
                    this);

            g.drawString((fcv.getCanUpTankTeamMembers().size() > 0) ? "全部乘降" : "没有坦克", fcv.getTankMenuCoorX() + (int) (47 * fcv.getProportion()),
                    (int) (46 * fcv.getProportion()) + fcv.getTankMenuCoorY());
            int i = 0;
            //牵引按键
            g.drawImage(ImageUtil.getImage("gamesayselectmenubody"), fcv.getTankMenuCoorX(),
                    (int) ((63 + 44 * i) * fcv.getProportion()) + fcv.getTankMenuCoorY(), (int) (184 * fcv.getProportion()),
                    (int) (44 * fcv.getProportion()), this);
            g.drawImage(ImageUtil.getImage("gamesayselectbutton"), fcv.getTankMenuCoorX() + (int) (18 * fcv.getProportion()),
                    (int) ((65 + 44 * i) * fcv.getProportion()) + fcv.getTankMenuCoorY(), (int) (149 * fcv.getProportion()),
                    (int) (40 * fcv.getProportion()), this);
            g.drawString(" 牵引", fcv.getTankMenuCoorX() + (int) (47 * fcv.getProportion()),
                    (int) ((90 + 44 * i) * fcv.getProportion()) + fcv.getTankMenuCoorY());
            i++;
            for (String playerid : fcv.getCanUpTankTeamMemberChNames()) {
                g.drawImage(ImageUtil.getImage("gamesayselectmenubody"), fcv.getTankMenuCoorX(),
                        (int) ((63 + 44 * i) * fcv.getProportion()) + fcv.getTankMenuCoorY(), (int) (184 * fcv.getProportion()),
                        (int) (44 * fcv.getProportion()), this);
                g.drawImage(ImageUtil.getImage("gamesayselectbutton"), fcv.getTankMenuCoorX() + (int) (18 * fcv.getProportion()),
                        (int) ((65 + 44 * i) * fcv.getProportion()) + fcv.getTankMenuCoorY(), (int) (149 * fcv.getProportion()),
                        (int) (40 * fcv.getProportion()), this);

                g.drawString(playerid + " 乘降", fcv.getTankMenuCoorX() + (int) (47 * fcv.getProportion()),
                        (int) ((90 + 44 * i) * fcv.getProportion()) + fcv.getTankMenuCoorY());
                i++;
            }


            g.drawImage(ImageUtil.getImage("gamesayselectmenufoot"), fcv.getTankMenuCoorX(),
                    (int) ((63 + 44 * i) * fcv.getProportion()) + fcv.getTankMenuCoorY(), (int) (184 * fcv.getProportion()),
                    (int) (19 * fcv.getProportion()), this);

            g.setColor(new Color(163, 163, 163));
            if (fcv.getTankMenuMouseEnterX() > -1 && fcv.getTankMenuMouseEnterY() > -1)
                g.fillRect(fcv.getTankMenuMouseEnterX(), fcv.getTankMenuMouseEnterY(), (int) (16 * fcv.getProportion()),
                        (int) (33 * fcv.getProportion()));

            if(fcv.isOpenUseTankMenuChild()){
                //打开子菜单了
                i = 0;
                int x = (int)(fcv.getTankMenuCoorX()+184 * fcv.getProportion());
                g.setColor(Color.BLACK);
                g.drawImage(ImageUtil.getImage("gamesayselectmenuhead"),x,(int) (44 * fcv.getProportion()) + fcv.getTankMenuCoorY(),
                        (int) (184 * fcv.getProportion()),
                        (int) (19 * fcv.getProportion()), this);
                for (String text : fcv.getCurSelectTankOnMap()) {
                    g.drawImage(ImageUtil.getImage("gamesayselectmenubody"), x,
                            (int) ((63 + 44 * i) * fcv.getProportion()) + fcv.getTankMenuCoorY(), (int) (184 * fcv.getProportion()),
                            (int) (44 * fcv.getProportion()), this);
                    g.drawImage(ImageUtil.getImage("gamesayselectbutton"), x + (int) (18 * fcv.getProportion()),
                            (int) ((65 + 44 * i) * fcv.getProportion()) + fcv.getTankMenuCoorY(), (int) (149 * fcv.getProportion()),
                            (int) (40 * fcv.getProportion()), this);

                    g.drawString(langLib.getNameOfId(text.split(",")[0]), x + (int) (47 * fcv.getProportion()),
                            (int) ((90 + 44 * i) * fcv.getProportion()) + fcv.getTankMenuCoorY());
                    i++;
                }
                g.drawImage(ImageUtil.getImage("gamesayselectmenufoot"), x,
                        (int) ((63 + 44 * i) * fcv.getProportion()) + fcv.getTankMenuCoorY(), (int) (184 * fcv.getProportion()),
                        (int) (19 * fcv.getProportion()), this);
            }
        }
    }

    @Override
    protected void setBounds() {
        font1 = new Font(FCRConstants.FONT_ELEGANT_BLACK, 0, (int) (17 * fcv.getProportion()));
    }
}
